package se.wangs.state;

import org.junit.Test;
import se.wangs.state.impl.OrderState;
import se.wangs.state.impl.ProductOutState;
import se.wangs.state.impl.TransportState;

public class StateClient {

    /**
     * 测试各个状态
     */
    @Test
    public void buyKeyboard() {
        //状态的保持与切换者
        JdLogistics jdLogistics = new JdLogistics();

        //接单状态
        OrderState orderState = new OrderState();
        jdLogistics.setLogisticsState(orderState);
        jdLogistics.doAction();

        //出库状态
        ProductOutState productOutState = new ProductOutState();
        jdLogistics.setLogisticsState(productOutState);
        jdLogistics.doAction();

        //运输状态
        TransportState transportState = new TransportState();
        jdLogistics.setLogisticsState(transportState);
        jdLogistics.doAction();
    }

    @Test
    public void allTest() {
        // 保存状态的上下文信息
        JdLogistics jdLogistics = new JdLogistics();

        // 首先接单
        OrderState orderState = new OrderState();
        // 开始处于接单状态
        jdLogistics.setLogisticsState(orderState);
        // 开始物流
        jdLogistics.doAction(); // 当前：OrderState；执行后：ProductOutState

        // 再次查询物流
        jdLogistics.doAction(); // 当前：ProductOutState；执行后：TransportState
        // 再次查询物流
        jdLogistics.doAction(); // 当前：TransportState；执行后：FinishedState
        // 再次查询物流
        jdLogistics.doAction(); // 当前：FinishedState；执行后：FinishedState
        // 再次查询物流
        jdLogistics.doAction(); // 当前：FinishedState；执行后：FinishedState
    }
}